//
//  AppDelegate.m
//  FanBei
//
//  Created by 哀木涕 on 2016/12/28.
//  Copyright © 2016年 chuxiangkeji. All rights reserved.
//

#import "AppDelegate.h"
#import "IQKeyboardManager.h"
#import "ALTabBarVC.h"
#import "FMDeviceManager.h"
#import "ALAppUpdateModel.h"
#import "AppDelegate+ALJPushHelper.h"
#import <AlibcTradeSDK/AlibcTradeSDK.h>
#import <AlibcTradeSDK/AlibcTradeShowParams.h>
#import <AlibcTradeSDK/AlibcTradeTaokeParams.h>
#import <AlibabaAuthSDK/ALBBSDK.h>
#import <AlibcTradeSDK/AlibcTradeService.h>

#define versionKey @"CFBundleVersion"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window.rootViewController = [[ALTabBarVC alloc]init];
    
    //配置同盾
    [self setTondun];
    //配置阿里百川SDK
    [self setAliBasicData];
    //键盘统一设定
    [self BA_KeyboardSetting];
    //设置导航栏样式
    [self setNavigationStyle];
    //设置tabbar颜色
    [self changeTabbarTitleColor];
    //检查版本更新
    [ALAppUpdateModel checkAppUpdate];
    //选择根视图
    [ALAppUpdateModel selectRootVC];
    //注册极光推送
    [self JPushApplication:application didFinishLaunchingWithOptions:launchOptions];
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
    [[AlibcTradeSDK sharedInstance] handleOpenURL:url]; // 如果百川处理过会返回YES
    return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    [[AlibcTradeSDK sharedInstance] handleOpenURL:url]; // 如果百川处理过会返回YES
    return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

#pragma mark 自定义方法
- (void)setRootVC{
    
}
- (void)setTondun{
    FMDeviceManager_t *AAAmanager= [FMDeviceManager sharedManager];
    NSMutableDictionary *options = [NSMutableDictionary dictionary];
    [options setValue:@"alading" forKey:@"partner"];
    [options setValue:@"allowd" forKey:@"allowd"];
    //    [options setValue:@"sandbox" forKey:@"env"];
    AAAmanager->initWithOptions(options);
}
- (void)setAliBasicData{
        [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
            NSLog(@"init success :");
        } failure:^(NSError *error) {
            NSLog(@"init failed :%@",error.description);
        }];
    [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];
    AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
    taokeParams.pid = TaoKePid;
    taokeParams.unionId = TaoKeUnionId;
    taokeParams.subPid = TaoKeSubPid;
        [[AlibcTradeSDK sharedInstance] setEnv:ALiEnvironmentRelease];
    [[AlibcTradeSDK sharedInstance] enableAuthVipMode];
    [[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];
        [[AlibcTradeSDK sharedInstance] setISVCode:My_isv_code];
    [[AlibcTradeSDK sharedInstance] setIsForceH5:NO];
}
- (void)BA_KeyboardSetting
{
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    manager.shouldResignOnTouchOutside = YES;
    manager.shouldToolbarUsesTextFieldTintColor = YES;
    manager.enableAutoToolbar = NO;
}
-(void)setNavigationStyle{
    self.window.backgroundColor = [UIColor whiteColor];
    if(IOS_VERSION >=8.0) [[UINavigationBar appearance] setTranslucent:NO];
    
    //去除文字
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];   //按钮颜色
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName, nil]]; //标题字体等属性
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//status bar的字体色，需要在info.plist设置View controller-based status bar appearance为NO
}
- (void)changeTabbarTitleColor{
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : MainColor} forState:UIControlStateSelected];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateNormal];
}

@end
